{block name="resources"}

{/block}
{block name="main"}
<!-- page -->
<form class="form-horizontal form-validate widthFixedForm">
    <input type="hidden" id="mansong_id" value="{$mansong_info['mansong_id']}"/>
    <input type="hidden" id="seleted_goods" value="3,1"/>
    <div class="screen-title">
        <span class="text">规则设置</span>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>活动名称</label>
        <div class="col-md-8">
            <input type="text" class="form-control" name="mansong_name" value="{$mansong_info['mansong_name']}" autocomplete="off">
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>优惠规则</label>
        <div class="col-md-8">
            <div class="form-table-group" style="width: auto;">
                <table class="table table-bordered table-auto-center table_rule">
                    <tr>
                        <td class="w-200">门槛</td>
                        <td >优惠方式</td>
                        <td>操作</td>
                    </tr>
                    {volist name="mansong_info['rule']" id="vo"}
                    <tr class="rule_set">
                        <td>
                            满<input type="text" id="price{$key+1}" name="price" value="{$vo['price']}" class="form-control number-form-control-100 ml-15 mr-15" min="0">元
                        </td>
                        <td>
                            <div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label"><input type="checkbox" class="discount_money" {if condition="$vo['discount'] gt 0"}checked{/if} id="discount{$key+1}" name="discountChk" coupontype="reduce{$key+1}"> 减金额</label>
                                    <div class="col-md-7 {if condition="$vo['discount'] eq 0"}hidden{/if}" showcoupontype="reduce{$key+1}" coupontype="reduce{$key+1}">
                                    <div class="input-group w-200">
                                        <input type="number" class="form-control" min="0" name="discount" value="{$vo['discount']}" id="discount_input{$key+1}">
                                        <div class="input-group-addon">元</div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-md-3 control-label"><input class="decorate" name="free_shipping" id="free_shipping{$key+1}" type="checkbox" {if condition="$vo['free_shipping'] eq 1"}checked{/if}> 免邮</label>
                            </div>
                            {if condition="$giftvoucher_status eq 1"}
                            <div class="form-group">
                                <label class="col-md-3 control-label"><input name="give_coupon" id="give_coupon" type="checkbox" {if condition="$vo['give_coupon'] gt 0"}checked{/if}> 送优惠券</label>
                                <div class="col-md-7 {if condition="$vo['give_coupon'] eq 0"}hidden{/if}" showcoupontype="giveconpon{$key+1}">
                                <select class="form-control select-form-control" id="give_coupon_select" />
                                {volist name="coupon_type_array['data']" id="vc"}
                                <option value="{$vc['coupon_type_id']}" {if condition="$vo['give_coupon'] eq $vc['coupon_type_id']"}selected{/if}>{$vc['coupon_name']}</option>
                                {/volist}
                                </select>
                                </div>
                            </div>
                            {/if}

                            {if condition="$gift_status eq 1"}
                            <div class="form-group">
                                <label class="col-md-3 control-label"><input name="give_gift" id="give_gift" type="checkbox" {if condition="$vo['gift_id'] gt 0"}checked{/if}> 送赠品</label>
                                <div class="col-md-7 {if condition="$vo['gift_id'] eq 0"}hidden{/if}" showcoupontype="giveconpon{$key+1}">
                                <select class="form-control select-form-control" id="gift_select" />
                                {volist name="gift_list_array['data']" id="vc"}
                                <option value="{$vc['promotion_gift_id']}" {if condition="$vo['gift_id'] eq $vc['promotion_gift_id']"}selected{/if}>{$vc['gift_name']}</option>
                                {/volist}
                                </select>
                            </div>
                            </div>
                            {/if}

                            {if condition="$giftvoucher_status eq 1"}
                            <div class="form-group">
                                <label class="col-md-3 control-label"><input name="give_giftvoucher" id="give_giftvoucher" type="checkbox" {if condition="$vo['gift_card_id'] gt 0"}checked{/if}> 送礼品券</label>
                                <div class="col-md-7 {if condition="$vo['gift_card_id'] eq 0"}hidden{/if}" showcoupontype="giveconpon{$key+1}">
                                <select class="form-control select-form-control" id="giftvoucher_select" />
                                {volist name="giftvoucher_list_array['data']" id="vc"}
                                <option value="{$vc['gift_voucher_id']}" {if condition="$vo['gift_card_id'] eq $vc['gift_voucher_id']"}selected{/if}>{$vc['giftvoucher_name']}</option>
                                {/volist}
                                </select>
                                </div>
                            </div>
                            {/if}
            </div>
            </td>
            <td><a href="javascript:;" class="text-danger del">删除</a></td>
            </tr>
            {/volist}
            <tr class="last-tr">
                <td colspan="3" class="text-left">
                    <a href="javascript:;" class="text-primary addRule">增加一个规则</a><span class="small-muted pl-15">最多增加五个</span>
                </td>
            </tr>
            </table>
        </div>
    </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>生效时间</label>
        <div class="col-md-8">
            <div class="v-datetime-input-control">
                <label for="effect_time">
                    <input type="text" class="form-control" id="effect_time" placeholder="请选择时间" value="{$mansong_info['start_time'] | timeStampTurnDate} - {$mansong_info['end_time'] | timeStampTurnDate}" autocomplete="off" name="effect_time" required>
                    <i class="icon icon-calendar"></i>
                    <input type="hidden" id="start_time" name="start_time" value="{$mansong_info['start_time'] | timeStampTurnDate}">
                    <input type="hidden" id="end_time" name="end_time" value="{$mansong_info['end_time'] | timeStampTurnDate}">
                </label>
            </div>
            <div class="help-block mb-0">开始时间点为选中日期的0:00:00，结束时间点为选中日期的23:59:59</div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label">活动说明</label>
        <div class="col-md-8">
            <textarea class="form-control resize_none" rows="4" name="remark">{$mansong_info['remark']}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label">优先级</label>
        <div class="col-md-8">
            <input type="text" class="form-control" name="level" placeholder="越大越优先" value="{$mansong_info['level']}">
        </div>
    </div>

    <div class="screen-title">
        <span class="text">活动商品</span>
    </div>
    <div class="form-group">
        <label class="col-md-2 control-label"><span class="text-bright">*</span>参加活动商品</label>
        <div class="col-md-5">
            <label class="radio-inline">
                <input type="radio" name="range_type" value="1" {if condition="$mansong_info['range_type'] eq 1"}checked="checked/"{/if}> 所有商品
            </label>
            <label class="radio-inline">
                <input type="radio" name="range_type" value="0" {if condition="$mansong_info['range_type'] eq 0"}checked="checked/"{/if}> 部分商品
            </label>
        </div>
    </div>
    <div class="form-group hidden" id="range_type">
        <label class="col-md-2 control-label"></label>
        <div class="col-md-9">
            <div>
                <ul class="nav nav-tabs v-nav-tabs" role="tablist">
                    <li role="presentation" class="active goods_list"><a href="#list" aria-controls="list" role="tab" data-toggle="tab" class="flex-auto-center">商品列表</a></li>
                    <li role="presentation" class="select_goods_list"><a href="#curr" aria-controls="curr" role="tab" data-toggle="tab" class="flex-auto-center">已选商品</a></li>
                    <div class="input-group search-input-group pull-right">
                        <input type="text" class="form-control" placeholder="商品名称" id="search_text">
                        <span class="input-group-btn"><a class="btn btn-primary search">搜索</a></span>
                    </div>
                </ul>
                <div class="tab-content">
                    <div role="tabpanel" class="tab-pane fade in active" id="list">
                        <table class="table v-table table-auto-center" style="width:100%;">
                            <thead>
                            <tr>
                                <th>商品信息</th>
                                <th>库存</th>
                                <th>店铺</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="goods_list">

                            </tbody>
                        </table>
                        <input type="hidden" id="pageIndex">
                        <nav aria-label="Page navigation" class="clearfix">
                            <ul id="page" class="pagination pull-right"></ul>
                        </nav>
                    </div>
                    <div role="tabpanel" class="tab-pane" id="curr">
                        <table class="table v-table table-auto-center" style="width:100%;">
                            <thead>
                            <tr>
                                <th>商品信息</th>
                                <th>库存</th>
                                <th>店铺</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="seleted_goods_list">


                            </tbody>
                        </table>
                        <input type="hidden" id="pageIndex2">
                        <nav aria-label="Page navigation" class="clearfix">
                            <ul id="page2" class="pagination pull-right"></ul>
                        </nav>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>

    <div class="form-group"></div>
    {if condition="$fullcut_info eq '1' "}

    {else}
    <div class="form-group">
        <label class="col-md-2 control-label"></label>
        <div class="col-md-8">
            <button class="btn btn-primary submit" href="javascript:void(0)" type="submit">保存</button>
            <a href="javascript:history.go(-1);" class="btn btn-default">返回</a>
        </div>
    </div>
    {/if}
</form>

<!-- page end -->
{/block}


{block name="script"}
<script>
    require(['util'],function(util){
        var addNum = '1';
        var range_type = ''
        // util.layDate("#start_time");
        // util.layDate("#end_time");
        util.layDate('#effect_time',true,function(value, date, endDate){
            var date1=date.year+'-'+date.month+'-'+date.date;
            var date2=endDate.year+'-'+endDate.month+'-'+endDate.date;
            if(value){
                $('#start_time').val(date1);
                $('#end_time').val(date2);
                $('#effect_time').parents('.form-group').removeClass('has-error');
            }
            else{
                $('#start_time').val('');
                $('#end_time').val('');
            }
        });

        $('body').on('change','.discount_money',function(){
            if($(this).prop('checked')){
                //$('div[showcoupontype='+$(this).attr('reduce')+']').removeClass('hidden')
                $(this).parent().next().removeClass('hidden')
                //$(this).removeClass('hidden')
            }else{
                //$('div[showcoupontype='+$(this).attr('reduce')+']').addClass('hidden')
                $(this).parent().next().addClass('hidden')
            }
        })


        //获取优惠券

        $('body').on('change','input[name="give_coupon"]',function(){
            if($(this).prop('checked')){
                $(this).parent().next().removeClass('hidden')
            }else{
                $(this).parent().next().addClass('hidden')
            }
        })

        $('body').on('change','input[name="give_gift"]',function(){
            if($(this).prop('checked')){
                $(this).parent().next().removeClass('hidden')
            }else{
                $(this).parent().next().addClass('hidden')
            }
        })

        $('body').on('change','input[name="give_giftvoucher"]',function(){
            if($(this).prop('checked')){
                $(this).parent().next().removeClass('hidden')
            }else{
                $(this).parent().next().addClass('hidden')
            }
        })

        // 添加规则
        var nums=5;
        $('.addRule').on('click',function(){
            var obj = $(".table_rule tbody .rule_set");
            addNum = obj.length;
            // if(addNum==0){
            //     addNum = 1;
            // }
            // addNum++;
        if(obj.length>4){
            util.message('活动规则最多添加5个');
        }
        else{
            nums++;
            var html = '<tr class="rule_set">';
                html += '<td>满<input type="number" id="price'+nums+'" name="price" required class="form-control number-form-control-100 ml-15 mr-15" min="0" autocomplete="off">元</td>';
                html +='<td>';
                html +='<div>';
                html +='<div class="form-group">';
                html +='<label class="col-md-3 control-label"><input data-name="discount" class="discount_money decorate" type="checkbox" id="discount'+nums+'" name="discountChk" coupontype="reduce'+nums+'"> 减金额</label>';
                html +='<div class="col-md-8 hidden" showcoupontype="reduce'+nums+'" coupontype="reduce'+nums+'">';
                html +='<div class="input-group w-200">';
                html +='<input type="number" class="form-control" min="0" name="discount" id="discount_input'+nums+'">';
                html +='<div class="input-group-addon">元</div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='<div class="form-group">';
                html +='<label class="col-md-3 control-label"><input class="decorate" name="free_shipping" id="free_shipping'+nums+'" type="checkbox"> 免邮</label>';
                html +='</div>';
                //优惠券
                if({$couponStatus}==1){
                    html +='<div class="form-group">';
                    html +='<label class="col-md-3 control-label"><input name="give_coupon" id="give_coupon" type="checkbox"> 送优惠券</label>';
                    html +='<div class="col-md-8 hidden" showcoupontype="giveconpon'+nums+'">';
                    html +='<select class="form-control select-form-control" id="give_coupon_select">';
                    if(coupon_type_list!='') {
                        var coupon_list = coupon_type_list.data;
                        coupon_list.forEach(function(v,k){
                            html +='<option value="'+v.coupon_type_id+'">'+v.coupon_name+'</option>';
                        });
                    }
                    html +='</select>';
                    html +='</div>';
                    html +='</div>';
                }

                //赠品
                if({$gift_status}==1){
                    html +='<div class="form-group">';
                    html +='<label class="col-md-3 control-label"><input name="give_gift" id="give_gift" type="checkbox"> 送赠品</label>';
                    html +='<div class="col-md-8 hidden" showcoupontype="gift'+nums+'">';
                    html +='<select class="form-control select-form-control" id="gift_select">';
                    if(gift_list!='') {
                        var coupon_list = gift_list.data;
                        coupon_list.forEach(function(v,k){
                            html +='<option value="'+v.promotion_gift_id+'">'+v.gift_name+'</option>';
                        });
                    }
                    html +='</select>';
                    html +='</div>';
                    html +='</div>';
                }

                //礼品券
                if({$giftvoucher_status}==1){
                    html +='<div class="form-group">';
                    html +='<label class="col-md-3 control-label"><input name="give_giftvoucher" id="give_giftvoucher" type="checkbox"> 送礼品券</label>';
                    html +='<div class="col-md-8 hidden" showcoupontype="giftvoucher'+nums+'">';
                    html +='<select class="form-control select-form-control" id="giftvoucher_select">';
                    if(giftvoucher_list!='') {
                        var g_list = giftvoucher_list.data;
                        g_list.forEach(function(v,k){
                            html +='<option value="'+v.gift_voucher_id+'">'+v.giftvoucher_name+'</option>';
                        });
                    }
                    html +='</select>';
                    html +='</div>';
                    html +='</div>';
                }
                html +='</div>';
                html +='</td>';
                html +='<td><a href="javascript:;" class="text-danger del">删除</a></td>';
                html +='</tr>';
                $('.last-tr').before(html);
        }

        })

        if($('input[name=type]').val() == '0'){
            $('#type0').show().siblings().hide();
        }else if($('input[name=type]').val() == '1'){
            $('#type1').show().siblings().hide();
        }else if($('input[name=type]').val() == '2'){
            $('#type2').show().siblings().hide();
        }
        $('input[name=type]').on('change',function(){
            $('#type'+$(this).val()).show().siblings().hide();
        })

        $('input[name=range_type]').on('change',function(){
            range_type = $(this).val()
            if($(this).val() == '0'){
                $('#activitygoods').removeClass('hidden');
            }else{
                $('#activitygoods').addClass('hidden');
            }

        })

        //删除规则
        $('body').on('click','.del',function(){
            $(this).parent().parent().remove();
        })


        //定义临时数组储存商品ID
        var temp_id = {$seleted_goods};
        if(temp_id!=null && temp_id!=''){

        }else{
            var temp_id = [];
        }
        //商品列表数据
        util.initPage(LoadingInfo);
        util.initPage(load_selected_goods,'page2');
        $('.search').on('click',function(){
            LoadingInfo(1);
        });

        function LoadingInfo(page_index) {
            var $goodsArr = new Array();
            var search_text = $("#search_text").val();
            var shop_id = {$shop_id};
            if($("input[name='range_type']:checked").val() == 0){
                $('#range_type').removeClass('hidden');
            }else{
                $('#range_type').addClass('hidden');
            }
            var seleted_goods = temp_id
            $.ajax({
                type : "post",
                url: "{:__URL('admin/addons/execute/addons/fullcut/controller/fullcut/action/getserchgoodslist')}",
                data : {
                    "page_index" : page_index,
                    "page_size" : $("#showNumber").val(),
                    "search_text" : search_text,
                    "shop_range_type":'',
                    "shop_id":shop_id
                },
                success : function(data) {
                    $data_array = data['data'];
                    var html = '';
                    var seleted_html = '';
                    if (data['data'].length > 0) {
                        for (var i = 0; i < data['data'].length; i++) {

                            var curr = data['data'][i];
                            if(jQuery.inArray(curr["goods_id"], $goodsArr) == "-1"){
                                $goodsArr.push(curr["goods_id"]);
                            }else{
                                continue;
                            }

                            html+='<tr id="html_'+data['data'][i]["goods_id"]+'" goodsid="'+data['data'][i]["goods_id"]+'">';
                            html+='<td>';
                            html+='<div class="media text-left">';
                            html+='<div class="media-left">';
                            html +='<div>';
                            if(data['data'][i]["picture_info"]['pic_cover']){
                                html +='<img src="'+__IMG(data['data'][i]["picture_info"]['pic_cover'])+'" width="60" height="60"></div></th>';
                            }else{
                                html +='<img src="__ROOT__/" width="60" height="60"></div></th>';
                            }
                            html +='</div>';
                            html+='<div class="media-body max-w-300">';
                            html+='<div class="line-2-ellipsis"><a href="'+__URLS('SHOP_MAIN/goods/goodsinfo&goodsid='+data['data'][i]["goods_id"])+'" target="_blank" class="new-window" title="'+data['data'][i]["goods_name"]+'">'+data['data'][i]["goods_name"]+'</a></div>';
                            html+='</div>';
                            html+='</div>';
                            html+='</td>';
                            html+='<td>';
                            html+=data['data'][i]["stock"];
                            html+='</td>';
                            html+='<td>';
                            html+=data['data'][i]["shop_name"];
                            html+='</td>';
                            html+='<td>';
                            if(jQuery.inArray(curr["goods_id"], seleted_goods) == "-1"){
                                html +='<a href="javascript:;" class="btn btn-default btn-sm btn-primary join" >参加活动</a>';
                            }else{
                                html +='<a href="javascript:;" class="btn btn-default btn-sm cancle" id="id_'+data['data'][i]["goods_id"]+'">取消参加</a>';
                            }
                            html+='<input type="hidden" name="goods_id" id="'+data['data'][i]["goods_id"]+'" value="'+data['data'][i]["goods_id"]+'">';
                            html+='</td>';
                            html+='</tr>';
                            //
                            // if (jQuery.inArray(curr["goods_id"], seleted_goods) != "-1") {
                            //     seleted_html = '<tr id="html_' + data['data'][i]["goods_id"] + '" goodsid="' + data['data'][i]["goods_id"] + '">' + html + '</tr>';
                            // }
                        }
                    } else {
                        html += '<tr align="center"><th colspan="4">暂无符合条件的数据记录</th></tr>';
                    }

                    $("#goods_list").html(html);
                    $('#page').paginator('option', {
                        totalCounts: data['total_count']  // 动态修改总数
                    });
                }
            });

        }

        function load_selected_goods(page_index){
            //动态增加已选择的
            var range = $('input[name="range"]:checked').val();
            var search_text = $("#search_text").val();
            var range_type = $("input[name='range_type']:checked").val();
            $("#seleted_goods_list").html('');
            if($("input[name='range_type']:checked").val() == 0){
                $('#range_type').removeClass('hidden');
            }else{
                $('#range_type').addClass('hidden');
            }
            var seleted_goods = temp_id;
            if(range_type==0) {
                var html = '';
                $.ajax({
                    type: "post",
                    url: "{:__URL('admin/addons/execute/addons/fullcut/controller/fullcut/action/getserchgoodslist')}",
                    data: {
                        "page_index":page_index,
                        "page_size": $("#showNumber").val(),
                        "search_text": search_text,
                        "shop_range_type": range,
                        "seleted_goods": seleted_goods
                    },
                    success: function (data) {
                        $data_array = data['data'];
                        if (data['data'].length > 0) {
                            for (var i = 0; i < data['data'].length; i++) {
                                var curr = data['data'][i];
                                html += '<tr id="html_' + data['data'][i]["goods_id"] + '" goodsid="' + data['data'][i]["goods_id"] + '">';
                                html += '<td>';
                                html += '<div class="media text-left">';
                                html += '<div class="media-left">';
                                html += '<div>';
                                if (data['data'][i]["picture_info"]['pic_cover']) {
                                    html += '<img src="' + __IMG(data['data'][i]["picture_info"]['pic_cover']) + '" width="60" height="60"></div></th>';
                                } else {
                                    html += '<img src="__ROOT__/" width="60" height="60"></div></th>';
                                }
                                html += '</div>';
                                html += '<div class="media-body max-w-300">';
                                html += '<div class="line-2-ellipsis"><a href="' + __URLS('SHOP_MAIN/goods/goodsinfo&goodsid=' + data['data'][i]["goods_id"]) + '" target="_blank" class="new-window" title="' + data['data'][i]["goods_name"] + '">' + data['data'][i]["goods_name"] + '</a></div>';
                                html += '</div>';
                                html += '</div>';
                                html += '</td>';
                                html += '<td>';
                                html += data['data'][i]["stock"];
                                html += '</td>';
                                html += '<td>';
                                html += data['data'][i]["shop_name"];
                                html += '</td>';
                                html += '<td>';
                                html += '<a href="javascript:;" class="btn btn-default btn-sm cancle" id="id_' + data['data'][i]["goods_id"] + '">取消参加</a>';
                                html += '<input type="hidden" name="goods_id" id="' + data['data'][i]["goods_id"] + '" value="' + data['data'][i]["goods_id"] + '">';
                                html += '</td>';
                                html += '</tr>';
                                //
                                // if (jQuery.inArray(curr["goods_id"], seleted_goods) != "-1") {
                                //     seleted_html = '<tr id="html_' + data['data'][i]["goods_id"] + '" goodsid="' + data['data'][i]["goods_id"] + '">' + html + '</tr>';
                                // }
                            }
                        } else {
                            html += '<tr align="center"><th colspan="4">暂无符合条件的数据记录</th></tr>';
                        }
                        $("#seleted_goods_list").append(html);
                    }
                });
            }
        }


        //自营全平台商品
        $('body').on('change','input[name=range]',function(){
                LoadingInfo(1);
        })

        //加入商品
        $('body').on('click','.join',function(){
            var id = $(this).next($("input[name='goods_id']")).val();
            $(this).removeClass('join');
            $(this).parent().html('<a class="btn btn-default btn-sm cancle" id="id_'+id+'" href="javascript:;">取消参加</a><input type="hidden" name="goods_id" value="'+id+'">');
            var html = $('#html_'+id).html();
            // var html = $(this).parent().parent().parent();
            $("#seleted_goods_list").append('<tr id="html_'+id+'" goodsid="'+id+'">'+html+'</tr>');
            temp_id.push(parseInt(id));
        })

        //取消参加
        $('body').on('click','.cancle',function(){
            var id = $(this).next($("input[name='goods_id']")).val();
            $('#seleted_goods_list #html_'+id+'').remove();
            $('#id_'+id+'').removeClass('cancle');
            $('#id_'+id+'').addClass('join btn-primary');
            $('#id_'+id+'').html("参加活动");
            temp_id.splice($.inArray(parseInt(id),temp_id), 1);
        })


        // 添加规则
        var flag = false;

        util.validate($('.form-validate'),function(form){
            if($(".table_rule tbody .rule_set").length>1){
                var type="2"
            }else{
                var type="1";
            }
            var range = 3;
            var level = $("input[name='level']").val();
            var status = $("input[name='status']:checked").val();
            var remark = $("textarea[name='remark']").val();
            var mansong_name = $("input[name='mansong_name']").val();
            var start_time = $("#start_time").val();
            var end_time = $("#end_time").val();
            var range_type = $("input[name='range_type']:checked").val();
            if(mansong_name.length==0 || start_time.lenght==0 || end_time.length==0){
                util.message('请将信息填写完整',"danger");
                return false;
            }

            // //参与商品
            // var obj = $("#seleted_goods_list tr");
            // var goods_id_array = '';
            // obj.each(function(i){
            //     goods_id_array += ','+obj.eq(i).attr("goodsid");
            // });
            // goods_id_array = goods_id_array.substring(1);
            if(temp_id == '' && range_type == 0){
                util.message('请选择参加活动的商品',"danger");
                return false;
            }
            //多级活动规则
            var rule = '';
            var obj = $(".table_rule tbody .rule_set");
            if(obj.length==0){
                util.message('请至少设置一种规则',"danger");
                return false;
            }
            for(var i=0;i < obj.length;i++){
                //满减送价格
                if(obj.eq(i).find('input[name="price"]').val() > 0){
                    var price = obj.eq(i).find('input[name="price"]').val();
                }else{
                    var price = 0;
                    util.message("请输入优惠门槛金额","danger");
                    return false;
                }
                //减现金
                if(obj.eq(i).find('input[name="discountChk"]').is(':checked') == true){
                    if(obj.eq(i).find('input[name="discount"]').val()==""){
                        util.message("请输入减免金额","danger");
                        obj.eq(i).find('input[name="discount"]').focus();
                        return false;
                    }
                    var discount = obj.eq(i).find('input[name="discount"]').val();
                }else{
                    var discount = 0;
                }
                //免邮
                if(obj.eq(i).find('input[name="free_shipping"]').is(':checked') == true){
                    var free_shipping = 1;
                }else{
                    var free_shipping = 0;
                }
                //优惠券
                if(obj.eq(i).find('#give_coupon').is(':checked') == true){
                    var give_coupon = obj.eq(i).find('#give_coupon_select option:selected').val();
                }else{
                    var give_coupon = 0;
                }
                //送赠品
                if(obj.eq(i).find('#give_gift').is(':checked') == true){
                    var give_gift = obj.eq(i).find('#gift_select option:selected').val();
                }else{
                    var give_gift = 0;
                }
                //送礼品券
                if(obj.eq(i).find('#give_giftvoucher').is(':checked') == true){

                    var give_giftvoucher = obj.eq(i).find('#giftvoucher_select option:selected').val();
                }else{
                    var give_giftvoucher = 0;
                }

                // if(discount+free_shipping+give_coupon+give_gift+give_giftvoucher == 0){
                //     util.message('请至少选择一种优惠方式', 'danger');
                //     return false;
                // }
                rule += ';'+price+','+discount+','+free_shipping+','+give_coupon+','+give_gift+','+give_giftvoucher;
            }
            rule = rule.substring(1);

            if(flag){
                return false;
            }
            flag = true;
            var shop_id = {$shop_id};
            var mansong_id = $("#mansong_id").val();
            $.ajax({
                type : "post",
                url : "{:__URL('admin/Menu/addonmenu?addons=editFullCut')}",
                data : {
                    'mansong_name' : mansong_name,
                    'level' : level,
                    'range' : range,
                    'status' : status,
                    'remark' : remark,
                    'start_time' : start_time,
                    'end_time' : end_time,
                    'range_type' : range_type,
                    'mansong_id':mansong_id,
                    'goods_id_array' : temp_id,
                    'rule':rule,
                    'type':type,
                    'shop_id':shop_id
                },
                success : function(data) {
                    if (data["code"] > 0) {
                        util.message(data["message"],'success',"{:__URL('admin/Menu/addonmenu?addons=fullCutList')}");
                    }else{
                        util.message("开始时间不能大于结束时间",'danger');
                        flag = false;
                    }
                }
            });


        })
        $(".select_goods_list").on('click',function(){
            $(".clearfix").hide();
        })
        $(".goods_list").on('click',function(){
            $(".clearfix").show();
        })

    })
</script>
{/block}